package com.enjoy.rpc;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

public class StackTraceUtil {
    /**
     * 取出throwable中的信息
     */
    public static String getStackTrace(Throwable throwable) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            throwable.printStackTrace(pw);
            return sw.toString();
        } finally {
            if (sw!=null) {
                try {
                    sw.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
    }
}
